package com.grendel.tubeyourmind.core
{
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	import mx.controls.Alert;

	public class SimpleRequest
	{
		private static var resFunction:Function;
		
		public static function doRequest(url:String, resultFunction:Function):void
		{
			resFunction = resultFunction;
			
			var userRequest:URLRequest = new URLRequest(url);
			var userLoader:URLLoader = new URLLoader();
			
			userLoader.addEventListener(IOErrorEvent.IO_ERROR, defaultErrorHandler);
			userLoader.addEventListener(Event.COMPLETE, resFunction);
			
			userLoader.load(userRequest);
		}
		
		private function res(event:Event):void
		{
			trace (event);
		}

		private static function defaultErrorHandler(event:IOErrorEvent):void
		{
			Alert.show(event.text, "ALARMMMMM!!");
		}
	}
}